﻿using System;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Web.Script.Serialization;

using EasyFMS.Common;
using EasyFMS.Model;
using Liger.Data;
using Liger.Common;
using Liger.Common.Extensions;
using Liger.Data.Extensions;
using EasyFMS.Service.Setting;
using System.Data;

namespace EasyFMS.Service
{
    /// <summary>
    /// 系统设置的数据库执行
    /// </summary>
    public class AjaxSystem
    {
        public static DbContext DB = DbHelper.Db;
        public HttpContext Context;

        public AjaxSystem()
        {
        }

        public AjaxSystem(HttpContext context)
        {
            this.Context = context;
        }

        /// <summary>
        /// 公用获取号码
        /// </summary>
        /// <returns></returns>
        public static AjaxResult GetSeqNo(string DoType, int PT)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pGetSeqNo] '" + DoType + "'," + PT + "");
                return AjaxResult.Success(infoSet.Tables[0].Rows[0]["SeqNo"], "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 公共执行判断SQL查询结果
        /// </summary>
        /// <returns></returns>
        public static AjaxResult CheckSql(string SQL)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet(SQL);
                if (infoSet.Tables[0].Rows.Count > 0)
                    return AjaxResult.Success("OK");
                else
                    return AjaxResult.Error("ER");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        } 
        /// <summary>
        /// 公共执行SQL语句
        /// </summary>
        /// <returns></returns>
        public static AjaxResult DoSql(string SQL)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet(SQL);
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        } 
        /// <summary>
        /// 增加 币种 
        /// </summary>
        public static AjaxResult AddCurrency(NameValueCollection form)
        {
            var entity = new bCurrency();
            entity.Load(form);
            return DB.InsertEntity<bCurrency>(entity);
        }
        /// <summary>
        /// 修改 币种 
        /// </summary>
        public static AjaxResult UpdateCurrency(NameValueCollection form)
        {
            var entity = DB.From<bCurrency>().Where(bCurrency._.UID == form["UID"]).ToFirst();
            entity.Attach();
            entity.Load(form);
            entity.UserModifyID = SysContext.CurrentUserID;
            entity.ModifyDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
            return DB.UpdateEntity<bCurrency>(entity); 
        }

        #region 基础数据
        /// <summary>
        /// 增加 基础数据 
        /// </summary>
        public static AjaxResult AddBaseData(NameValueCollection form)
        {
            var entity = new tBaseData();
            entity.Load(form);
            try
            {
                var uid = DB.Insert<tBaseData>(entity);
                return DB.GetEntity<tBaseData>(tBaseData._.UID == uid);
            }
            catch (Exception te)
            {
                return AjaxResult.Error(te.Message);
            }
        }
        /// <summary>
        /// 修改 基础数据 
        /// </summary>
        public static AjaxResult UpdateBaseData(NameValueCollection form)
        {
            var entity = DB.From<tBaseData>().Where(tBaseData._.UID == form["UID"]).ToFirst();
            entity.Attach();
            entity.Load(form);
            entity.UserModifyID = SysContext.CurrentUserID;
            entity.ModifyDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
            try
            {
                var uid = DB.Update<tBaseData>(entity);
                return DB.GetEntity<tBaseData>(tBaseData._.UID == form["UID"]);
            }
            catch (Exception te)
            {
                return AjaxResult.Error(te.Message);
            }
        }
        #endregion

        #region 参数设置
        /// <summary>
        /// 增加 参数设置 
        /// </summary>
        public static AjaxResult AddParameter(NameValueCollection form)
        {
            var entity = new tParameter();
            entity.Load(form);
            try
            {
                var uid = DB.Insert<tParameter>(entity);
                return DB.GetEntity<tParameter>(tParameter._.UID == uid);
            }
            catch (Exception te)
            {
                return AjaxResult.Error(te.Message);
            }
        }
        /// <summary>
        /// 修改 参数设置 
        /// </summary>
        public static AjaxResult UpdateParameter(NameValueCollection form)
        {
            var entity = DB.From<tParameter>().Where(tParameter._.UID == form["UID"]).ToFirst();
            entity.Attach();
            entity.Load(form);
            entity.UserModifyID = SysContext.CurrentUserID;
            entity.ModifyDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
            try
            {
                var uid = DB.Update<tParameter>(entity);
                return DB.GetEntity<tParameter>(tParameter._.UID == form["UID"]);
            }
            catch (Exception te)
            {
                return AjaxResult.Error(te.Message);
            }
        }
        #endregion

        #region 实体内容
        /// <summary>
        /// 更新实体额度 
        /// </summary>
        public static AjaxResult EntityCreditUpdate(NameValueCollection form)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pEntityCreditUpdate] " + form["UID"] + "," + form["EntityID"] + ",'" + form["DeptCode"] + "','" + form["FeeType"] + "'," + form["InsteadAmount"] + "," + form["InsteadDays"] + ",'" + form["Note"] + "' ," + SysContext.CurrentUserID + "");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        #endregion

        #region 账单内容
        /// <summary>
        /// 增加 账单内容 
        /// </summary>
        public static AjaxResult AddBilling(NameValueCollection form)
        {
            var entity = new bBilling();
            entity.Load(form);
            try
            {
                var uid = DB.Insert<bBilling>(entity);
                return DB.GetEntity<bBilling>(bBilling._.UID == uid);
            }
            catch (Exception te)
            {
                return AjaxResult.Error(te.Message);
            }
        }
        /// <summary>
        /// 修改 账单内容 
        /// </summary>
        public static AjaxResult UpdateBilling(NameValueCollection form)
        {
            var entity = DB.From<bBilling>().Where(bBilling._.UID == form["UID"]).ToFirst();
            entity.Attach();
            entity.Load(form);
            entity.UserModifyID = SysContext.CurrentUserID;
            entity.ModifyDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
            try
            {
                var uid = DB.Update<bBilling>(entity);
                return DB.GetEntity<bBilling>(bBilling._.UID == form["UID"]);
            }
            catch (Exception te)
            {
                return AjaxResult.Error(te.Message);
            }
        }
        #endregion

        #region 用户相关
        /// <summary>
        /// 执行用户登出
        /// </summary>
        /// <returns></returns>
        public static AjaxResult loginOut()
        {
            SysContext.ClearUserStatus();
            return AjaxResult.Success("退出OK");
        }
        /// <summary>
        /// 密码修改
        /// </summary>
        /// <param name="USERID"></param>
        /// <param name="OLDPWD"></param>
        /// <param name="NEWPWD"></param>
        /// <returns></returns>
        public static AjaxResult ChangePWD(int USERID,string OLDPWD,string NEWPWD)
        {
            try
            {
                if (DB.From<tUser>().Where(tUser._.UserID == USERID && tUser._.Password == OLDPWD).Any())
                {
                    DataSet infoSet = DB.ExecuteDataSet("UPDATE [dbo].[tUser] SET Password = '" + NEWPWD + "' WHERE UserID = " + USERID + " ");
                    return AjaxResult.Success("OK");
                }
                else
                {
                    return AjaxResult.Error("旧密码不正确");
                }
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }

        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <returns></returns>
        public static AjaxResult loginIn()
        {
            try
            {
                if (SysContext.CurrentUserID == 0)
                {
                    return AjaxResult.Error("登录超时");
                }
                var tempUser = new { userid = SysContext.CurrentUserID, deptid = SysContext.CurrentRoleID, username = SysContext.CurrentUserTitle, deptname=SysContext.CurrentRoleName};
                return AjaxResult.Success(tempUser,"OK");
            }
            catch (Exception ss)
            {
                return AjaxResult.Error(ss.Message);
            }
        }

        /// <summary>
        /// 获取用户权限信息
        /// </summary>
        /// <returns></returns>
        public static AjaxResult getAuthInfo(int menuID)
        {
            try
            {
                if (SysContext.CurrentUserID == 0)
                {
                    return AjaxResult.Error("登录超时");
                }
                string authdata = string.Empty;
                var dataAuth = DB.ExecuteDataSet("SELECT * FROM vRightUserModule WHERE UserCode = '" + SysContext.CurrentUserID + "' AND ModuleTreeUID = " + menuID + "");
                for (int i = 0, l = dataAuth.Tables[0].Rows.Count; i < l; i++)
                {
                    authdata += dataAuth.Tables[0].Rows[i]["ModuleVerb"].ToString() + ";";
                }
                return AjaxResult.Success(new { userData = authdata.Substring(0, authdata.Length - 1) }, "OK");
            }
            catch (Exception ss)
            {
                return AjaxResult.Error(ss.Message);
            }
        }
        /// <summary>
        /// 用户加载部门
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="SELECTUID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult LoadDept(string UID, string SELECTUID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pUserDepartmentUpdate] '" + UID.ToString() + "','" + SELECTUID + "'," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 移除 用户加载部门
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult RemoveDept(int UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pDelUserDepartment] " + UID + "," + USERID + "");
                return AjaxResult.Success("移除成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        #endregion

        #region 支票信息
        /// <summary>
        /// 增加 支票信息 
        /// </summary>
        public static AjaxResult AddCheck(NameValueCollection form)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckUpdate] @UID=0,@Amount='" + form["Amount"] + "',@Bank='" + form["Bank"] + "', @CheckNo='" + form["CheckNo"] + "',@CheckType=" + form["CheckType"] + ", @PurchaseDate='" + Convert.ToDateTime(form["PurchaseDate"]) + "', @UserID=" + SysContext.CurrentUserID + ",@Note='" + form["Note"] + "'");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 修改 支票信息 
        /// </summary>
        public static AjaxResult UpdateCheck(NameValueCollection form)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckUpdate] @UID=" + form["UID"] + ",@Amount='" + form["Amount"] + "',@Bank='" + form["Bank"] + "', @CheckNo='" + form["CheckNo"] + "',@CheckType=" + form["CheckType"] + ", @PurchaseDate='" + Convert.ToDateTime(form["PurchaseDate"]) + "', @UserID=" + SysContext.CurrentUserID + ",@Note='" + form["Note"] + "'");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }

        /// <summary>
        /// 修改 支票信息 1
        /// </summary>
        public static AjaxResult UpdateCheck1(string UID, int CHECKTYPE, string CHECKDATE, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckUpdate1] @sUID='" + UID + "',@CheckType=" + CHECKTYPE + ",@CheckDate='" + CHECKDATE + "',@UserID=" + USERID + "");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 修改 支票信息 2
        /// </summary>
        public static AjaxResult UpdateCheck2(string UID, string CHECKDATE, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckUpdate2] @sUID='" + UID + "',@CheckDate='" + CHECKDATE + "', @UserID=" + USERID + "");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 修改 支票信息 3
        /// </summary>
        public static AjaxResult UpdateCheck3(string UID, string AMOUNT,int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckUpdate3] @sUID='" + UID + "',@Amount=" + (string.IsNullOrEmpty(AMOUNT) ? "0" : AMOUNT) + ", @UserID=" + USERID + "");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 修改 支票信息 4
        /// </summary>
        public static AjaxResult UpdateCheck4(string UID, int USERID, string NOTE)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckUpdate4] @sUID='" + UID + "',@UserID=" + USERID + ",@Note='" + NOTE + "'");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 删除 支票信息 
        /// </summary>
        public static AjaxResult RemoveCheck(int UID,int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pDelCheck] @UID=" + UID.ToString() + ",@UserID=" + USERID + "");
                return AjaxResult.Success("删除成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 批量增加 支票信息 
        /// </summary>
        public static AjaxResult AddBatchCheck(NameValueCollection form)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckAdd] '" + form["Bank"] + "','" + form["From"] + "'," + form["Qty"] + ",'" + Convert.ToDateTime(form["PurchaseDate"]) + "','" + form["CheckType"] + "'," + SysContext.CurrentUserID + "");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        #endregion

        #region 支票申请
        /// <summary>
        /// 增加 支票申请信息 
        /// </summary>
        public static AjaxResult AddCheckApply(NameValueCollection form)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckApplyUpdate] 0,'" + Convert.ToDateTime(form["CheckApplyDate"]) + "','" + form["DeptCode"] + "'," + form["Qty"] + ", '" + form["Note"] + "' ," + SysContext.CurrentUserID + "");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 修改 支票申请信息 
        /// </summary>
        public static AjaxResult UpdateCheckApply(NameValueCollection form)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckApplyUpdate] " + form["UID"] + ",'" + Convert.ToDateTime(form["CheckApplyDate"]) + "','" + form["DeptCode"] + "'," + form["Qty"] + ", '" + form["Note"] + "' ," + SysContext.CurrentUserID + "");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 增加 支票申请信息 
        /// </summary>
        public static AjaxResult AddCheckApply2(NameValueCollection form)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckApplyUpdate2] 0,'" + Convert.ToDateTime(form["CheckApplyDate"]) + "','" + form["DeptCode"] + "','" + form["DeptCode2"] + "'," + form["Qty"] + ", '" + form["Note"] + "' ," + SysContext.CurrentUserID + "");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 修改 支票申请信息 
        /// </summary>
        public static AjaxResult UpdateCheckApply2(NameValueCollection form)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckApplyUpdate2] " + form["UID"] + ",'" + Convert.ToDateTime(form["CheckApplyDate"]) + "','" + form["DeptCode"] + "','" + form["DeptCode2"] + "'," + form["Qty"] + ", '" + form["Note"] + "' ," + SysContext.CurrentUserID + "");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }

        /// <summary>
        /// 删除 支票申请信息  
        /// </summary>
        public static AjaxResult RemoveCheckApply(int UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pDelCheckApply] @UID=" + UID.ToString() + ",@UserID=" + USERID + "");
                return AjaxResult.Success("删除成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 提交 支票申请信息  
        /// </summary>
        public static AjaxResult SubmitCheckApply(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckApplyCommitEx] '" + UID.ToString() + "',0," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet),"OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 撤销 支票申请信息  
        /// </summary>
        public static AjaxResult UndoCheckApply(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckApplyCommitEx] '" + UID.ToString() + "',1," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 部门审核 支票申请信息  
        /// </summary>
        public static AjaxResult VerifyCheckApply(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckApplyVerifyEx] '" + UID.ToString() + "',0," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 部门撤销审核 支票申请信息  
        /// </summary>
        public static AjaxResult VerifyUndoCheckApply(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckApplyVerifyEx] '" + UID.ToString() + "',1," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 部门拒绝 支票申请信息  
        /// </summary>
        public static AjaxResult RejectCheckApply(string UID, string REJECTNOTE, int VERB, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckApplyReject] '" + UID.ToString() + "'," + VERB.ToString() + ",'" + REJECTNOTE + "'," + USERID + "");
                return AjaxResult.Success("加载拒绝内容成功。");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 财务审核 支票申请信息  
        /// </summary>
        public static AjaxResult AuditCheckApply(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckApplyAuditEx] '" + UID.ToString() + "',0," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 财务撤销审核 支票申请信息  
        /// </summary>
        public static AjaxResult AuditUndoCheckApply(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckApplyAuditEx] '" + UID.ToString() + "',1," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 财务拒绝 支票申请信息  
        /// </summary>
        public static AjaxResult RejectCheckApply2(string UID, string RjectNote,int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckApplyReject] '" + UID.ToString() + "',2,'" + RjectNote + "'," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }        
        #endregion

        #region 支票转移
        /// <summary>
        /// 支票号码 转移验证
        /// </summary>
        /// <param name="USERID"></param>
        /// <param name="CHECKNO"></param>
        /// <returns></returns>
        public static AjaxResult CheckCHECKNo(int USERID, string CHECKNO)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("SELECT C.CheckNo, C.DeptCode, D.Name AS DeptName FROM cCheck C JOIN tDepartment D ON C.DeptCode = D.Code WHERE CheckNo = '"+ CHECKNO +"' AND C.CheckStatus = 3 AND EXISTS ( SELECT 1 FROM tUserDepartment UD JOIN tUser U ON UD.UserID = U.UserID WHERE UD.UserID = '"+ USERID.ToString() +"'  AND  UD.DepartmentID = D.UID )");
                if(infoSet.Tables[0].Rows.Count == 0)
                    return AjaxResult.Error("NULL");
                else
                    return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 增加 支票转移信息 
        /// </summary>
        public static AjaxResult AddCheckMove(NameValueCollection form)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckMoveUpdate] 0,'" + form["CheckMoveNo"] + "','" + Convert.ToDateTime(form["CheckMoveDate"]) + "'," + form["CHECKNO"] + "," + form["DeptCodeFM"] + "," + form["DeptCodeTO"] + ", '" + form["Note"] + "' ," + SysContext.CurrentUserID + "");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 修改 支票转移信息 
        /// </summary>
        public static AjaxResult UpdateCheckMove(NameValueCollection form)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckMoveUpdate] " + form["UID"] + ",'" + form["CheckMoveNo"] + "','" + Convert.ToDateTime(form["CheckMoveDate"]) + "'," + form["CHECKNO"] + "," + form["DeptCodeFM"] + "," + form["DeptCodeTO"] + ", '" + form["Note"] + "'," + SysContext.CurrentUserID + "");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 删除 支票转移信息 
        /// </summary>
        public static AjaxResult RemoveCheckMove(int UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pDelCheckMove] @UID=" + UID.ToString() + ",@UserID=" + USERID + "");
                return AjaxResult.Success("删除成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 提交 支票转移信息  
        /// </summary>
        public static AjaxResult SubmitCheckMove(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckMoveCommitEx] '" + UID.ToString() + "',0," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 撤销 支票申请信息  
        /// </summary>
        public static AjaxResult UndoCheckMove(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckMoveCommitEx] '" + UID.ToString() + "',1," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }

        /// <summary>
        /// 部门审核 支票转移信息  
        /// </summary>
        public static AjaxResult VerifyCheckMove(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckMoveVerifyEx] '" + UID.ToString() + "',0," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 撤销 支票申请信息  
        /// </summary>
        public static AjaxResult VerifyUndoCheckMove(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckMoveVerifyEx] '" + UID.ToString() + "',1," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }

        /// <summary>
        /// 财务审核 支票转移信息  
        /// </summary>
        public static AjaxResult AuditCheckMove(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckMoveAuditEx] '" + UID.ToString() + "',0," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 撤销 支票申请信息  
        /// </summary>
        public static AjaxResult AuditUndoCheckMove(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckMoveAuditEx] '" + UID.ToString() + "',1," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        
        /// <summary>
        /// 撤销 支票分配信息  
        /// </summary>
        public static AjaxResult RemoveCheckAllocate(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pDelCheckApplyDtl] '" + UID.ToString() + "'," + USERID + "");
                return AjaxResult.Success("删除成功。");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 确认 支票分配信息  
        /// </summary>
        public static AjaxResult ConfirmCheckAllocate(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckApplyAllocate] '" + UID.ToString() + "',0," + USERID + "");
                return AjaxResult.Success("确认成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 取消 支票分配信息  
        /// </summary>
        public static AjaxResult CancelCheckAllocate(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckApplyAllocate] '" + UID.ToString() + "',1," + USERID + "");
                return AjaxResult.Success("撤销成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }

        /// <summary>
        /// 执行 支票分配信息  
        /// </summary>
        public static AjaxResult CheckAllocate(string UID,string SELECTUID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckAllocateEx] '" + UID.ToString() + "','"+ SELECTUID +"'," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 执行 支票确认信息  
        /// </summary>
        public static AjaxResult ConfirmCheck(string UID, string TransType, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckConfirmEx] '" + UID.ToString() + "','"+ TransType +"',0," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 撤销 支票确认信息  
        /// </summary>
        public static AjaxResult UndoConfirmCheck(string UID, string TransType, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheckConfirmEx] '" + UID.ToString() + "','" + TransType + "',1," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        ///  支票快速转移信息  
        /// </summary>
        public static AjaxResult CheckToMove(string UID, string DeptCodeTo, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCheck2Move] '" + UID.ToString() + "'," + DeptCodeTo + "," + USERID + "");
                return AjaxResult.Success("转移成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        #endregion

        #region 代垫信息
        /// <summary>
        /// 校验报关单号
        /// </summary>
        /// <param name="OrderNo"></param>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public static AjaxResult CheckDeclareOrderNo(int USERID, string ORDERNO)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("SELECT O.DeptName1, O.DeptName2, O.CustomerName, O.DealinName,O.OrderNo FROM vOrderDeclare O WHERE O.DeclareNo1 = '" + ORDERNO + "' AND EXISTS ( SELECT 1 FROM tUserDepartment UD JOIN tDepartment D ON ud.DepartmentID = d.UID JOIN tUser U  ON ud.UserID = u.UserID WHERE U.UserID = " + USERID + " AND ( D.Code = O.DeptCode1 OR D.Code = O.DeptCode2))");
                if (infoSet.Tables[0].Rows.Count == 1)
                    return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
                else
                    return AjaxResult.Error("NULL");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 删除 代垫信息  
        /// </summary>
        public static AjaxResult RemoveInstead(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pDelInstead] '" + UID.ToString() + "'," + USERID + "");
                return AjaxResult.Success("删除成功。");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 增加 代垫信息 
        /// </summary>
        public static AjaxResult AddInstead(NameValueCollection form)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pInsteadUpdate] 0,'" + form["OrderNo"] + "','" + form["DeclareNo"] + "','" + form["FeeType"] + "'," + form["Amount"] + "," + SysContext.CurrentUserID + "");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 修改 代垫信息 
        /// </summary>
        public static AjaxResult UpdateInstead(NameValueCollection form)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pInsteadUpdate] " + form["UID"] + ",'" + form["OrderNo"] + "','" + form["DeclareNo"] + "','" + form["FeeType"] + "'," + form["Amount"] + "," + SysContext.CurrentUserID + "");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 提交 代垫信息
        /// </summary>
        /// <param name="form"></param>
        /// <returns></returns>
        public static AjaxResult SubmitInstead(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pInsteadCommit] '" + UID.ToString() + "',0," + USERID +"");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 撤销提交 代垫信息
        /// </summary>
        /// <param name="form"></param>
        /// <returns></returns>
        public static AjaxResult UndoInstead(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pInsteadCommit] '" + UID.ToString() + "',1," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 申请 代垫信息
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="RETURNDATE"></param>
        /// <param name="APPLYNOTE"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult AddInsteadApply(int UID,string RETURNDATE,string APPLYNOTE, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pInsteadApply] " + UID + ",'"+ RETURNDATE +"','"+ APPLYNOTE +"'," + USERID + "");
                return AjaxResult.Success("申请成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 拒绝 代垫信息
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="TYPE"></param>
        /// <param name="REJECTNOTE"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult DoInsteadReject(int UID, int VERB, string REJECTNOTE, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pInsteadReject] " + UID + "," + VERB + ",'" + REJECTNOTE + "'," + USERID + "");
                return AjaxResult.Success("加载拒绝代垫内容成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 代垫审核
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult VerifyInstead(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pInsteadVerify] '" + UID.ToString() + "',0," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        ///  取消代垫审核
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult UndoVerifyInstead(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pInsteadVerify] '" + UID.ToString() + "',1," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 代垫授权
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult AuditInstead(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pInsteadAudit] '" + UID.ToString() + "',0," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 代垫取消授权
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult UndoAuditInstead(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pInsteadAudit] '" + UID.ToString() + "',1," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 代垫收款复核
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult GetCheckInstead(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pInsteadGetCheck] '" + UID.ToString() + "',0," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 代垫消收款复核
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult UndoGetCheckInstead(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pInsteadGetCheck] '" + UID.ToString() + "',1," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 执行 付款核销
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <param name="PayTypeCode"></param>
        /// <param name="AccountNo"></param>
        /// <param name="CheckNo"></param>
        /// <returns></returns>
        public static AjaxResult VerifyInsteadPay(int UID, int USERID, string PayTypeCode, string AccountNo, string CheckNo)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pInsteadPay] " + UID + ",0,"+ PayTypeCode +",'"+AccountNo+"','"+CheckNo+"'," + USERID + "");
                return AjaxResult.Success("付款核销成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 执行 取消付款核销
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult UndoVerifyInsteadPay(int UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pInsteadPay] " + UID + ",1,'','',''," + USERID + "");
                return AjaxResult.Success("付款核销成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 代垫导出信息  
        /// </summary>
        public static AjaxResult InsteadExport(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pInsteadExport] '" + UID.ToString() + "'," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        #endregion

        #region 成本信息
        /// <summary>
        /// 增加 成本信息
        /// </summary>
        public static AjaxResult AddCost(NameValueCollection form)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCostUpdate] 0," + form["BillID"] + ",'" + form["SupplyCode"] + "','" + form["PayStatus"]  + "','" + form["FeeType"] + "','" + form["PayTypeCode"] + "','" + form["AccountNo"] + "','" + form["CheckNo"] + "','" + form["Currency"] + "'," + form["Price"] + "," + form["Qty"] + ", '" + form["Note"] + "'," + SysContext.CurrentUserID + "");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 修改 成本信息
        /// </summary>
        public static AjaxResult UpdateCost(NameValueCollection form)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCostUpdate] " + form["UID"] + "," + form["BillID"] + ",'" + form["SupplyCode"] + "','" + form["PayStatus"] + "','" + form["FeeType"] + "','" + form["PayTypeCode"] + "','" + form["AccountNo"] + "','" + form["CheckNo"] + "','" + form["Currency"] + "'," + form["Price"] + "," + form["Qty"] + ", '" + form["Note"] + "'," + SysContext.CurrentUserID + "");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 删除 成本信息
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult RemoveCost(int UID,int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pDelCost] "+ UID +","+ USERID +"");
                return AjaxResult.Success("删除成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 对账 成本信息
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult CollateCost(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCostCollate] '" + UID + "',0," + USERID + "");
                return AjaxResult.Success("成本对账成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 撤销对账 成本信息
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult UndoCollateCost(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCostCollate] '" + UID + "',1," + USERID + "");
                return AjaxResult.Success("成本对账撤销成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 获取成本发票信息
        /// </summary>
        /// <param name="UID"></param>
        /// <returns></returns>
        public static AjaxResult GetCostNoInfo(int UID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("SELECT [UID],[CollateNo],[CostNO],[CostType],[TaxRate],[Amount],[Amount2],[Note] FROM dbo.cCostNo WHERE CollateNo = (SELECT CollateNo FROM dbo.vCostCollate WHERE UID = " + UID + ")");
                if(infoSet.Tables[0].Rows.Count == 1)
                    return AjaxResult.Success(new Liger.Common.JSON.DataTableJSONSerializer().Serialize(infoSet.Tables[0]), "OK");
                else
                    return AjaxResult.Error("没有信息登记");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 修改 成本发票信息
        /// </summary>
        /// <param name="UID"></param>
        /// <returns></returns>
        public static AjaxResult UpdateCostNo(NameValueCollection form)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCostNoUpdate] " + form["UID"] + ",'" + form["CostNO"] + "'," + form["TaxRate"] + "," + form["Amount2"] + ",'" + form["Note"] + "'," + SysContext.CurrentUserID + "");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 确认 成本信息
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult CostConfirm(int UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCostConfirm] " + UID + ",0," + USERID + "");
                return AjaxResult.Success("成本确认成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }

        /// <summary>
        /// 撤销确认 成本信息
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult UndoCostConfirm(int UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCostConfirm] " + UID + ",1," + USERID + "");
                return AjaxResult.Success("成本撤销确认成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 请款 成本信息
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult CostBill(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCostBilling] '" + UID + "',0," + USERID + "");
                return AjaxResult.Success("成本请款成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 撤销请款 成本信息
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult UndoCostBill(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCostBilling] '" + UID + "',1," + USERID + "");
                return AjaxResult.Success("成本撤销请款成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 执行 成本核销
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <param name="PayTypeCode"></param>
        /// <param name="AccountNo"></param>
        /// <param name="CheckNo"></param>
        /// <returns></returns>
        public static AjaxResult CostPay(string UID, int USERID, string PayTypeCode, string AccountNo, string CheckNo)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCostPay] '" + UID + "',0," + PayTypeCode + ",'" + AccountNo + "','" + CheckNo + "'," + USERID + "");
                return AjaxResult.Success("成本核销成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 执行 取消成本核销
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult UndoCostPay(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCostPay] '" + UID + "',1,'','',''," + USERID + "");
                return AjaxResult.Success("成本核销取消成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        ///  导出成本
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult CostExport(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCostExport] '" + UID.ToString() + "'," + USERID + "");
                return AjaxResult.Success("导出成本成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 获取流水号
        /// </summary>
        /// <param name="OrderNo"></param>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public static AjaxResult CheckBillOrderNo(int USERID, string ORDERNO)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("SELECT UID,BillNo FROM cBill O WHERE O.OrderNo = '" + ORDERNO + "' AND BillStatus = 1 AND EXISTS ( SELECT 1 FROM tUserDepartment UD JOIN tDepartment D ON ud.DepartmentID = d.UID JOIN tUser U  ON ud.UserID = u.UserID WHERE U.UserID = " + USERID + " AND ( D.Code = O.DeptCode1 OR D.Code = O.DeptCode2))");
                if (infoSet.Tables[0].Rows.Count == 1)
                    return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
                else
                    return AjaxResult.Error("NULL");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }


        /// <summary>
        /// 部门审批 成本信息
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult AuditCost(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCostAudit] '" + UID + "',0," + USERID + "");
                return AjaxResult.Success("部门审批成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 部门审批 成本信息
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult UndoAuditCost(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCostAudit] '" + UID + "',1," + USERID + "");
                return AjaxResult.Success("部门撤销审批成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 入账营运部审批 成本信息
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult VerifyCost(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCostVerify] '" + UID + "',0," + USERID + "");
                return AjaxResult.Success("入账营运部审批成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 入账营运部审批 成本信息
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult UndoVerifyCost(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCostVerify] '" + UID + "',1," + USERID + "");
                return AjaxResult.Success("入账营运部撤销审批成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }

        /// <summary>
        /// 付款营运部审批 成本信息
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult AgreeCost(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCostAgree] '" + UID + "',0," + USERID + "");
                return AjaxResult.Success("营运部审批成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 营运部审批 成本信息
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult UndoAgreeCost(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCostAgree] '" + UID + "',1," + USERID + "");
                return AjaxResult.Success("营运部撤销审批成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 付款财务部审批 成本信息
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult FinancyCost(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCostFinancy] '" + UID + "',0," + USERID + "");
                return AjaxResult.Success("付款财务部审批成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 付款财务部审批 成本信息
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult UndoFinancyCost(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pCostFinancy] '" + UID + "',1," + USERID + "");
                return AjaxResult.Success("付款财务部撤销审批成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }

        #endregion

        #region 收入信息
        /// <summary>
        /// 增加 收入信息
        /// </summary>
        public static AjaxResult AddIncome(NameValueCollection form)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pIncomeUpdate] 0," + form["BillID"] + ",'" + form["FeeType"] + "'," + form["Price"] + "," + form["Qty"] + ", '" + form["Note"] + "'," + SysContext.CurrentUserID + "");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 修改 收入信息
        /// </summary>
        public static AjaxResult UpdateIncome(NameValueCollection form)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pIncomeUpdate] " + form["UID"] + "," + form["BillID"] + ",'" + form["FeeType"] + "'," + form["Price"] + "," + form["Qty"] + ", '" + form["Note"] + "'," + SysContext.CurrentUserID + "");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 删除 收入信息
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult RemoveIncome(int UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pDelIncome] " + UID + "," + USERID + "");
                return AjaxResult.Success("删除成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        #endregion

        #region 账单信息
        /// <summary>
        /// 拷贝 账单信息
        /// </summary>
        public static AjaxResult CopyBill(int UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pBillCopy] " + UID + "," + USERID + "");
                return AjaxResult.Success("账单拷贝成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 修改 账单信息
        /// </summary>
        public static AjaxResult UpdateBill(NameValueCollection form)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pBillUpdate] " + form["UID"] + "," + form["Currency"] + ", '" + form["Note"] + "'," + SysContext.CurrentUserID + "");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 删除 账单信息
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult RemoveBill(int UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pDelBill] " + UID + "," + USERID + "");
                return AjaxResult.Success("删除成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 提交 账单信息
        /// </summary>
        public static AjaxResult SubmitBill(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pBillCommitEx] '" + UID + "',0," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 撤销提交 账单信息
        /// </summary>
        public static AjaxResult UndoSubmitBill(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pBillCommitEx] '" + UID + "',1," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 对账 账单信息
        /// </summary>
        public static AjaxResult CollateBill(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pBillSumEx] '" + UID + "'");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 确认对账 账单信息
        /// </summary>
        public static AjaxResult BillCollate(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pBillCollate] '" + UID + "',0,"+ USERID +"");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 撤销对账 账单信息
        /// </summary>
        public static AjaxResult UndoCollateBill(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pBillCollate] '" + UID + "',1," + USERID + "");
                return AjaxResult.Success("撤销对账成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 审核 账单信息
        /// </summary>
        public static AjaxResult VerifyBill(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pBillVerifyEx] '" + UID + "',0," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 撤销审核 账单信息
        /// </summary>
        public static AjaxResult UndoVerifyBill(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pBillVerifyEx] '" + UID + "',1," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 合并 账单信息
        /// </summary>
        public static AjaxResult MergerBill(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pBillMerger] '" + UID + "',0," + USERID + "");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 撤销合并 账单信息
        /// </summary>
        public static AjaxResult UndoMergerBill(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pBillMerger] '" + UID + "',1," + USERID + "");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 获取发票信息
        /// </summary>
        /// <param name="UID"></param>
        /// <returns></returns>
        public static AjaxResult GetBillInvoiceInfo(int UID, int TYPEID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pBillVoucher] " + UID + ","+ TYPEID +"," + USERID + "");
                if (infoSet.Tables[0].Rows.Count == 1)
                    return AjaxResult.Success(new Liger.Common.JSON.DataTableJSONSerializer().Serialize(infoSet.Tables[0]), "OK");
                else
                    return AjaxResult.Error("没有信息登记");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 制单信息
        /// </summary>
        public static AjaxResult InvoiceBill(int UID,int TYPEID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pBillinvoice] " + UID + ","+TYPEID+"," + USERID + "");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 作废 发票
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult CancelInvoice(int UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pInvoiceInvalid] " + UID + "," + USERID + "");
                return AjaxResult.Success("发票作废成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 红冲 发票
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult RedInvoice(int UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pInvoiceRed] " + UID + "," + USERID + "");
                return AjaxResult.Success("发票红冲成功");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 发票凭证导出
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult InvoiceImport(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pIncomeExport] '" + UID + "'," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 收款
        /// </summary>
        /// <param name="UID"></param>
        /// <param name="USERID"></param>
        /// <returns></returns>
        public static AjaxResult GetIncome(int UID, string SELECTUID, string SELECTTYPE, string SELECTGET, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pGetIncome] " + UID + ",'" + SELECTUID + "','" + SELECTTYPE + "','" + SELECTGET + "'," + USERID + "");
                return AjaxResult.Success("OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 确认 账单信息
        /// </summary>
        public static AjaxResult ConfirmBill(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pBillConfirmEx] '" + UID + "',0," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        /// <summary>
        /// 撤销确认 账单信息
        /// </summary>
        public static AjaxResult UndoConfirmBill(string UID, int USERID)
        {
            try
            {
                DataSet infoSet = DB.ExecuteDataSet("EXEC [dbo].[pBillConfirmEx] '" + UID + "',1," + USERID + "");
                return AjaxResult.Success(new Liger.Common.JSON.DataSetJSONSerializer().Serialize(infoSet), "OK");
            }
            catch (Exception aa)
            {
                return AjaxResult.Error(aa.Message);
            }
        }
        #endregion
    }
}